package com.gouwudai.gobbs.dao.impl;

import java.util.List;

import org.apache.log4j.Logger;

import com.gouwudai.gobbs.common.IPageList;
import com.gouwudai.gobbs.dao.IBlackListDAO;
import com.gouwudai.gobbs.pojo.TbbsBlackList;
import com.litt.core.common.PageParam;

/**
 * 
 * <pre>
 *  Title:分类/版面黑名单DAO
 *  Description: 分类/版面黑名单DAO 
 * </pre>
 * 
 * @author <a href="mailto:littcai@hotmail.com">空心大白菜</a>
 * @date 2007-6-21
 * @version 1.0
 */
public class BlackListDAOImpl extends BaseDAOImpl implements IBlackListDAO
{
	private static final Logger logger = Logger.getLogger(BlackListDAOImpl.class);	
	
	/**
	 * 保存黑名单
     * @param tbbsBlackList
	 */
	public void save(TbbsBlackList tbbsBlackList)
	{    		
		super.saveObject(tbbsBlackList);		
	}
	
	/**
	 * 读取黑名单信息
     * @param id
	 * @return
	 */
	public TbbsBlackList load(Integer id)
	{
		return (TbbsBlackList)super.loadObject(TbbsBlackList.class, id);
	} 
    
    /**
     * 更新黑名单
     * @param tbbsBlackList
     */
    public void update(TbbsBlackList tbbsBlackList)
    {           
        super.updateObject(tbbsBlackList);        
    }
    
    /**
     * 删除一条黑名单
     * @param blackId 黑名单ID
     */
    public void delete(Integer blackId)
    {
        super.deleteObject(TbbsBlackList.class.getName(),"blackId",blackId);
    }
    
    /**
	 * 批量删除黑名单
     * @param blackIds 多个黑名单ID
	 */
    public void deleteBatch(String blackIds)
    {
        super.deleteObjects(TbbsBlackList.class.getName(),"blackId",blackIds);
    }
    
    /**
     * 查询某一用户某一版面的黑名单
     * @param classId
     * @param userId
     * @return List
     */
    public List listUserClass(Integer classId,Integer userId)
    {
        String listHql = "from TbbsBlackList obj where obj.classId="+classId+" and obj.userId="+userId;
        return super.listAll(listHql);        
    }
  
    
    /**
     * 查询指定用户的黑名单列表.
     * 
     * @param pageParam 分页查询参数
     * 
     * @return IPageList
     * 
     */
    public IPageList listPageByUser(PageParam pageParam)
    {	
        Integer userId = pageParam.getIntegerCond("userId");
        
        StringBuilder listSql = new StringBuilder("SELECT A.*,B.DICT_CONTENT AS BLACK_TYPE_NAME FROM TbbsBlackList A,TbbsDictParam B WHERE A.USER_ID=");
    	listSql.append(userId);
    	listSql.append(" AND (B.DICT_TYPE='BL01' AND B.DICT_VALUE=A.BLACK_TYPE)");
    	return super.listSqlPage(listSql.toString(),pageParam.getPageIndex(),pageParam.getPageSize());
    } 
    
    /**
     * 查询指定版面的黑名单列表.
     * 
     * @param pageParam 分页查询参数
     * 
     * @return IPageList
     * 
     */
    public IPageList listPageByClass(PageParam pageParam)
    {   
        Integer classId = pageParam.getIntegerCond("classId");
        
        StringBuilder listSql = new StringBuilder("SELECT A.*,B.DICT_CONTENT AS BLACK_TYPE_NAME,C.LOGIN_ID,C.USER_NAME FROM TbbsBlackList A,TbbsDictParam B,TbbsUserInfo C WHERE A.CLASS_ID=");
        listSql.append(classId);
        listSql.append(" AND (B.DICT_TYPE='BL01' AND B.DICT_VALUE=A.BLACK_TYPE) AND A.USER_ID=C.USER_ID");
        return super.listSqlPage(listSql.toString(),pageParam.getPageIndex(),pageParam.getPageSize());
    }     

}
